
# coding:utf-8

from lib import flux, al, sip

TypeDict = {
    'View':flux.View,
    'ImgView':flux.ImgView,
    'TextView':flux.TextView,
    'RichTextView':flux.RichTextView,
    'Custom':flux.View,
}

def new_view_from_dict(data):
    from system.map import MapManager
    from gui import ui

    m = MapManager()
    t = data['class_name'].encode('utf-8')

    if t == 'View':
        v = flux.View()
        v.SetSize(*data['size'])
    elif t == 'ImgView':
        v = flux.ImgView()
        v.SetSprite(data['sprite'].encode('utf-8'))
        v.SetSize(*data['size'])
    elif t == 'TextView':
        v = flux.TextView('wqy')
        v.SetText(data['text'].encode('utf-8'))
    elif t == 'RichTextView':
        v = flux.RichTextView('wqy')
        v.SetText(data['text'].encode('utf-8'))
    elif t == 'Custom':
        v = flux.View()
        v.SetSize(*data['size'])

    v.custom = True if t == 'Custom' else False

    v.SetPos(*data['pos'])
    v.SetAngle(data['angle'])
    v.SetColor(*data['color'])
    v.SetVisible(data['visible'])
    v.SetLayer(data['layer'])

    v.name = data['name'].encode('utf-8')
    v.class_name = t
    v.SetAnchor(m.map_top_left)
    return v
